﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IWS.SiteManager.Core
{
	[Serializable]
	public class SiteManagerContext
	{
		/// <summary>
		/// Gets or sets the current section selection.
		/// </summary>
		public string CurrentSection { get; set; }
		public string SiteHostName { get; set; }


		public static SiteManagerContext Current
		{
			get
			{
				var context = System.Web.HttpContext.Current;
				if (context != null && context.Session != null)
				{
					var sm = context.Session[Constants.SiteManagerContextKey] as SiteManagerContext;
					if (sm == null)
					{
						sm = new SiteManagerContext();
						sm.LoadDefaults();
						context.Session[Constants.SiteManagerContextKey] = sm;
					}
					return sm;
				}

				throw new ApplicationException("Session state not available.");
			}
		}

		public SiteManagerContext()
		{
		}

		public void LoadDefaults()
		{
			this.SiteHostName = SettingCache.Current.GetSetting(Constants.SiteHostname).Value;
		}
	}
}
